﻿using KqAutoDesign.Models;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace KqAutoDesign.SonViews
{
    /// <summary>
    /// WorkFlowCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class ParamDictionaryWd : Window, INotifyPropertyChanged
    {
        public ParamDictionaryWd()
        {
            InitializeComponent();
            DataContext = this;
            GlobalData.InitGlobalDictionary();
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propName));
            }
        }

        public GroupParams TotalParams
        {
            get { return GlobalData.GlobalParams; }
        }

        private GroupScriptParam _gsp;
        public GroupScriptParam Gsp
        {
            get { return _gsp; }
            set
            {
                if (_gsp != value)
                {
                    _gsp = value;
                    RaisePropertyChanged(nameof(Gsp));
                }
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        private void Close_action(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }

        private void Confirm_action(object sender, RoutedEventArgs e)
        {
            DialogResult=true;
            Close();
        }

        private void fucDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGrid dg = sender as DataGrid;
            if (dg != null)
            {
                Point aP = e.GetPosition(dg);//返回鼠标指针相对于指定元素的位置。
                IInputElement obj = dg.InputHitTest(aP);//返回坐标上的当前元素中的输入元素
                DependencyObject target = obj as DependencyObject;
                while (target != null)
                {
                    if (target is DataGridRow)
                    {
                        DialogResult = true;
                        Close();
                    }
                    target = VisualTreeHelper.GetParent(target);
                }
            }
        }
    }
}
